﻿namespace JunFan.Tests.UnitTests
{
    using System.Collections.Generic;
    using Domain;
    using FluentAssertions;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Infrastructure;

    [TestClass]
    public class ListingItems
    {
        [TestInitialize]
        public void InitializeBoard()
        {
            UnitTestContext.InitBoard();
        }

        /// <summary>
        /// Given: A list of items, some not started, some started and some completed
        /// When: Ask for all non started items
        /// Then: Should return all items of the list that are not started
        /// </summary>
        [TestMethod]
        public void ShouldListAllNonStartedItems()
        {
            Given.CompletedItem
                .Build(7)
                .Create(UnitTestContext.ItemRepositoryMock);

            Given.StartedItem
                .Build(4)
                .Create(UnitTestContext.ItemRepositoryMock);

            IEnumerable<Item> backlogItems = Given.NewItem
                                                .Build(9)
                                                .Create(UnitTestContext.ItemRepositoryMock);

            IEnumerable<Item> resultItems = UnitTestContext.Board.GetBacklogItems();

            resultItems.ShouldBeEquivalentTo(backlogItems);
        }

        /// <summary>
        /// Given: A list of items, some non completed and some completed
        /// When: Ask for all active items
        /// Then: Should return all items of the list that are not complete
        /// </summary>
        [TestMethod]
        public void ShouldListAllInProgressItems()
        {
            IEnumerable<Item> inProgressItems = Given.StartedItem
                                                .Build(7)
                                                .Create(UnitTestContext.ItemRepositoryMock);

            Given.NewItem
                .Build(9)
                .Create(UnitTestContext.ItemRepositoryMock);

            Given.CompletedItem
                .Build(10)
                .Create(UnitTestContext.ItemRepositoryMock);

            IEnumerable<Item> resultItems = UnitTestContext.Board.GetInProgressItems();

            resultItems.ShouldAllBeEquivalentTo(inProgressItems);
        }

        /// <summary>
        /// Given: A list of items, some non completed and some completed
        /// When: Ask for all active items
        /// Then: Should return all items of the list that are completed
        /// </summary>
        [TestMethod]
        public void ShouldListAllCompletedItems()
        {
            Given.NewItem
                 .Build(7)
                 .Create(UnitTestContext.ItemRepositoryMock);

            Given.StartedItem
                .Build(12)
                .Create(UnitTestContext.ItemRepositoryMock);

            IEnumerable<Item> completedItems = Given.CompletedItem
                                                .Build(8)
                                                .Create(UnitTestContext.ItemRepositoryMock);

            IEnumerable<Item> resultItems = UnitTestContext.Board.GetCompletedItems();

            resultItems.ShouldAllBeEquivalentTo(completedItems);
        }
    }
}
